using com.byt.suce.db.dao;
using System;
using System.Data;
using System.Data.Common;
using com.byt.webcore;
using System.Collections.Generic;
using MYLSOFT.JsonSimple;
using System.Data.SqlClient;

namespace com.byt.suce.db.mapper {

    public class PkgDr : AbstractDataAccessObject , IPkgDr {

        public PkgDr() {
        }

        public PkgDr.AprobGetbyidParam aprobGetbyid(Connection conn, Dictionary<string, string> map) {
            PkgDr.AprobGetbyidParam param = newAprobGetbyidParam(map);
            aprobGetbyid(conn, param);
            return param;
        }

        public PkgDr.AprobGetbyidParam aprobGetbyid(Connection conn, JSONObject json) {
            PkgDr.AprobGetbyidParam param = newAprobGetbyidParam(json);
            aprobGetbyid(conn, param);
            return param;
        }

        public PkgDr.AprobGetbyidParam aprobGetbyid(Connection conn) {
            PkgDr.AprobGetbyidParam param = newAprobGetbyidParam();
            aprobGetbyid(conn, param);
            return param;
        }

        public void aprobGetbyid(Connection conn, PkgDr.AprobGetbyidParam param) {
            DbCommand cmd = conn.CreateCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "[dbo].DR__aprob_getbyid";
            DbParameter par = null;
            // iddr
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@iddr";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.Int32;
            if (param.Iddr == null)
                par.Value = DBNull.Value;
            else
                par.Value = param.Iddr;
            // cur_out
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@cur_out";
            par.Direction = ParameterDirection.InputOutput;
            par.DbType = DbType.Object;
            par.Value = DBNull.Value;
            DataSet ds = new DataSet();
            DataAdapter da = new SqlDataAdapter((SqlCommand)cmd);
            da.Fill(ds);
            param.CurOut = (DbDataReader)ds.Tables[0].CreateDataReader();
        }

        public PkgDr.AprobUpdateParam aprobUpdate(Connection conn, Dictionary<string, string> map) {
            PkgDr.AprobUpdateParam param = newAprobUpdateParam(map);
            aprobUpdate(conn, param);
            return param;
        }

        public PkgDr.AprobUpdateParam aprobUpdate(Connection conn, JSONObject json) {
            PkgDr.AprobUpdateParam param = newAprobUpdateParam(json);
            aprobUpdate(conn, param);
            return param;
        }

        public PkgDr.AprobUpdateParam aprobUpdate(Connection conn) {
            PkgDr.AprobUpdateParam param = newAprobUpdateParam();
            aprobUpdate(conn, param);
            return param;
        }

        public void aprobUpdate(Connection conn, PkgDr.AprobUpdateParam param) {
            DbCommand cmd = conn.CreateCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "[dbo].DR__aprob_update";
            DbParameter par = null;
            // iddr
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@iddr";
            par.Direction = ParameterDirection.InputOutput;
            par.DbType = DbType.Int32;
            if (param.Iddr == null)
                par.Value = DBNull.Value;
            else
                par.Value = param.Iddr;
            // numedr
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@numedr";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.String;
            par.Size = 50;
            if (string.IsNullOrEmpty(param.Numedr))
                par.Value = DBNull.Value;
            else
                par.Value = param.Numedr;
            // numfile
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@numfile";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.String;
            par.Size = 50;
            if (string.IsNullOrEmpty(param.Numfile))
                par.Value = DBNull.Value;
            else
                par.Value = param.Numfile;
            // fechbroad
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@fechbroad";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.DateTime;
            if (param.Fechbroad == null)
                par.Value = DBNull.Value;
            else
                par.Value = param.Fechbroad;
            // fechvalida
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@fechvalida";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.DateTime;
            if (param.Fechvalida == null)
                par.Value = DBNull.Value;
            else
                par.Value = param.Fechvalida;
            cmd.ExecuteNonQuery();
            if(DBNull.Value.Equals(cmd.Parameters["@iddr"].Value))
                param.Iddr = null;
            else
                param.Iddr = (int?)cmd.Parameters["@iddr"].Value;
        }

        public PkgDr.DenegGetbyidParam denegGetbyid(Connection conn, Dictionary<string, string> map) {
            PkgDr.DenegGetbyidParam param = newDenegGetbyidParam(map);
            denegGetbyid(conn, param);
            return param;
        }

        public PkgDr.DenegGetbyidParam denegGetbyid(Connection conn, JSONObject json) {
            PkgDr.DenegGetbyidParam param = newDenegGetbyidParam(json);
            denegGetbyid(conn, param);
            return param;
        }

        public PkgDr.DenegGetbyidParam denegGetbyid(Connection conn) {
            PkgDr.DenegGetbyidParam param = newDenegGetbyidParam();
            denegGetbyid(conn, param);
            return param;
        }

        public void denegGetbyid(Connection conn, PkgDr.DenegGetbyidParam param) {
            DbCommand cmd = conn.CreateCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "[dbo].DR__deneg_getbyid";
            DbParameter par = null;
            // iddr
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@iddr";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.Int32;
            if (param.Iddr == null)
                par.Value = DBNull.Value;
            else
                par.Value = param.Iddr;
            // cur_out
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@cur_out";
            par.Direction = ParameterDirection.InputOutput;
            par.DbType = DbType.Object;
            par.Value = DBNull.Value;
            DataSet ds = new DataSet();
            DataAdapter da = new SqlDataAdapter((SqlCommand)cmd);
            da.Fill(ds);
            param.CurOut = (DbDataReader)ds.Tables[0].CreateDataReader();
        }

        public PkgDr.DenegUpdateParam denegUpdate(Connection conn, Dictionary<string, string> map) {
            PkgDr.DenegUpdateParam param = newDenegUpdateParam(map);
            denegUpdate(conn, param);
            return param;
        }

        public PkgDr.DenegUpdateParam denegUpdate(Connection conn, JSONObject json) {
            PkgDr.DenegUpdateParam param = newDenegUpdateParam(json);
            denegUpdate(conn, param);
            return param;
        }

        public PkgDr.DenegUpdateParam denegUpdate(Connection conn) {
            PkgDr.DenegUpdateParam param = newDenegUpdateParam();
            denegUpdate(conn, param);
            return param;
        }

        public void denegUpdate(Connection conn, PkgDr.DenegUpdateParam param) {
            DbCommand cmd = conn.CreateCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "[dbo].DR__deneg_update";
            DbParameter par = null;
            // iddr
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@iddr";
            par.Direction = ParameterDirection.InputOutput;
            par.DbType = DbType.Int32;
            if (param.Iddr == null)
                par.Value = DBNull.Value;
            else
                par.Value = param.Iddr;
            // numedr
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@numedr";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.String;
            par.Size = 50;
            if (string.IsNullOrEmpty(param.Numedr))
                par.Value = DBNull.Value;
            else
                par.Value = param.Numedr;
            // numfile
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@numfile";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.String;
            par.Size = 50;
            if (string.IsNullOrEmpty(param.Numfile))
                par.Value = DBNull.Value;
            else
                par.Value = param.Numfile;
            // fechbroad
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@fechbroad";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.DateTime;
            if (param.Fechbroad == null)
                par.Value = DBNull.Value;
            else
                par.Value = param.Fechbroad;
            // fechvalida
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@fechvalida";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.DateTime;
            if (param.Fechvalida == null)
                par.Value = DBNull.Value;
            else
                par.Value = param.Fechvalida;
            // mensaje
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@mensaje";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.String;
            par.Size = 4000;
            if (string.IsNullOrEmpty(param.Mensaje))
                par.Value = DBNull.Value;
            else
                par.Value = param.Mensaje;
            cmd.ExecuteNonQuery();
            if(DBNull.Value.Equals(cmd.Parameters["@iddr"].Value))
                param.Iddr = null;
            else
                param.Iddr = (int?)cmd.Parameters["@iddr"].Value;
        }

        public PkgDr.InsertParam insert(Connection conn, Dictionary<string, string> map) {
            PkgDr.InsertParam param = newInsertParam(map);
            insert(conn, param);
            return param;
        }

        public PkgDr.InsertParam insert(Connection conn, JSONObject json) {
            PkgDr.InsertParam param = newInsertParam(json);
            insert(conn, param);
            return param;
        }

        public PkgDr.InsertParam insert(Connection conn) {
            PkgDr.InsertParam param = newInsertParam();
            insert(conn, param);
            return param;
        }

        public void insert(Connection conn, PkgDr.InsertParam param) {
            DbCommand cmd = conn.CreateCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "[dbo].DR__insert";
            DbParameter par = null;
            // iddr
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@iddr";
            par.Direction = ParameterDirection.InputOutput;
            par.DbType = DbType.Int32;
            if (param.Iddr == null)
                par.Value = DBNull.Value;
            else
                par.Value = param.Iddr;
            // idsolicitud
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@idsolicitud";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.Int32;
            if (param.Idsolicitud == null)
                par.Value = DBNull.Value;
            else
                par.Value = param.Idsolicitud;
            // idversion
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@idversion";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.Int32;
            if (param.Idversion == null)
                par.Value = DBNull.Value;
            else
                par.Value = param.Idversion;
            // idtipodr
            par = cmd.CreateParameter();
            cmd.Parameters.Add(par);
            par.ParameterName = "@idtipodr";
            par.Direction = ParameterDirection.Input;
            par.DbType = DbType.String;
            par.Size = 1;
            if (string.IsNullOrEmpty(param.Idtipodr))
                par.Value = DBNull.Value;
            else
                par.Value = param.Idtipodr;
            cmd.ExecuteNonQuery();
            if(DBNull.Value.Equals(cmd.Parameters["@iddr"].Value))
                param.Iddr = null;
            else
                param.Iddr = (int?)cmd.Parameters["@iddr"].Value;
        }

        public PkgDr.AprobGetbyidParam newAprobGetbyidParam() {
            return new AprobGetbyidParam();
        }

        public PkgDr.AprobGetbyidParam newAprobGetbyidParam(Dictionary<string, string> map) {
            return new AprobGetbyidParam(map);
        }

        public PkgDr.AprobGetbyidParam newAprobGetbyidParam(JSONObject json) {
            return new AprobGetbyidParam(json);
        }

        public PkgDr.AprobUpdateParam newAprobUpdateParam() {
            return new AprobUpdateParam();
        }

        public PkgDr.AprobUpdateParam newAprobUpdateParam(Dictionary<string, string> map) {
            return new AprobUpdateParam(map);
        }

        public PkgDr.AprobUpdateParam newAprobUpdateParam(JSONObject json) {
            return new AprobUpdateParam(json);
        }

        public PkgDr.DenegGetbyidParam newDenegGetbyidParam() {
            return new DenegGetbyidParam();
        }

        public PkgDr.DenegGetbyidParam newDenegGetbyidParam(Dictionary<string, string> map) {
            return new DenegGetbyidParam(map);
        }

        public PkgDr.DenegGetbyidParam newDenegGetbyidParam(JSONObject json) {
            return new DenegGetbyidParam(json);
        }

        public PkgDr.DenegUpdateParam newDenegUpdateParam() {
            return new DenegUpdateParam();
        }

        public PkgDr.DenegUpdateParam newDenegUpdateParam(Dictionary<string, string> map) {
            return new DenegUpdateParam(map);
        }

        public PkgDr.DenegUpdateParam newDenegUpdateParam(JSONObject json) {
            return new DenegUpdateParam(json);
        }

        public PkgDr.InsertParam newInsertParam() {
            return new InsertParam();
        }

        public PkgDr.InsertParam newInsertParam(Dictionary<string, string> map) {
            return new InsertParam(map);
        }

        public PkgDr.InsertParam newInsertParam(JSONObject json) {
            return new InsertParam(json);
        }

        public class AprobGetbyidParam {

            private int? iddr;
            private DbDataReader curOut;

            public AprobGetbyidParam() {
            }

            public AprobGetbyidParam(Dictionary<string, string> map) {
                ResourceManager.populateDtoFromMap(this, map);
            }

            public AprobGetbyidParam(JSONObject json) {
                ResourceManager.populateDtoFromMap(this, json);
            }

            public int? Iddr {
                get { return iddr; }
                set { this.iddr = value; }
            }

            public DbDataReader CurOut {
                get { return curOut; }
                set { this.curOut = value; }
            }

            public void setValuesFromMap(Dictionary<string, string> map) {
                ResourceManager.populateDtoFromMap(this, map);
            }

            public void setValuesFromMap(JSONObject json) {
                ResourceManager.populateDtoFromMap(this, json);
            }

        }

        public class AprobUpdateParam {

            private int? iddr;
            private string numedr;
            private string numfile;
            private DateTime? fechbroad;
            private DateTime? fechvalida;

            public AprobUpdateParam() {
            }

            public AprobUpdateParam(Dictionary<string, string> map) {
                ResourceManager.populateDtoFromMap(this, map);
            }

            public AprobUpdateParam(JSONObject json) {
                ResourceManager.populateDtoFromMap(this, json);
            }

            public int? Iddr {
                get { return iddr; }
                set { this.iddr = value; }
            }

            public string Numedr {
                get { return numedr; }
                set { this.numedr = value; }
            }

            public string Numfile {
                get { return numfile; }
                set { this.numfile = value; }
            }

            public DateTime? Fechbroad {
                get { return fechbroad; }
                set { this.fechbroad = value; }
            }

            public DateTime? Fechvalida {
                get { return fechvalida; }
                set { this.fechvalida = value; }
            }

            public void setValuesFromMap(Dictionary<string, string> map) {
                ResourceManager.populateDtoFromMap(this, map);
            }

            public void setValuesFromMap(JSONObject json) {
                ResourceManager.populateDtoFromMap(this, json);
            }

        }

        public class DenegGetbyidParam {

            private int? iddr;
            private DbDataReader curOut;

            public DenegGetbyidParam() {
            }

            public DenegGetbyidParam(Dictionary<string, string> map) {
                ResourceManager.populateDtoFromMap(this, map);
            }

            public DenegGetbyidParam(JSONObject json) {
                ResourceManager.populateDtoFromMap(this, json);
            }

            public int? Iddr {
                get { return iddr; }
                set { this.iddr = value; }
            }

            public DbDataReader CurOut {
                get { return curOut; }
                set { this.curOut = value; }
            }

            public void setValuesFromMap(Dictionary<string, string> map) {
                ResourceManager.populateDtoFromMap(this, map);
            }

            public void setValuesFromMap(JSONObject json) {
                ResourceManager.populateDtoFromMap(this, json);
            }

        }

        public class DenegUpdateParam {

            private int? iddr;
            private string numedr;
            private string numfile;
            private DateTime? fechbroad;
            private DateTime? fechvalida;
            private string mensaje;

            public DenegUpdateParam() {
            }

            public DenegUpdateParam(Dictionary<string, string> map) {
                ResourceManager.populateDtoFromMap(this, map);
            }

            public DenegUpdateParam(JSONObject json) {
                ResourceManager.populateDtoFromMap(this, json);
            }

            public int? Iddr {
                get { return iddr; }
                set { this.iddr = value; }
            }

            public string Numedr {
                get { return numedr; }
                set { this.numedr = value; }
            }

            public string Numfile {
                get { return numfile; }
                set { this.numfile = value; }
            }

            public DateTime? Fechbroad {
                get { return fechbroad; }
                set { this.fechbroad = value; }
            }

            public DateTime? Fechvalida {
                get { return fechvalida; }
                set { this.fechvalida = value; }
            }

            public string Mensaje {
                get { return mensaje; }
                set { this.mensaje = value; }
            }

            public void setValuesFromMap(Dictionary<string, string> map) {
                ResourceManager.populateDtoFromMap(this, map);
            }

            public void setValuesFromMap(JSONObject json) {
                ResourceManager.populateDtoFromMap(this, json);
            }

        }

        public class InsertParam {

            private int? iddr;
            private int? idsolicitud;
            private int? idversion;
            private string idtipodr;

            public InsertParam() {
            }

            public InsertParam(Dictionary<string, string> map) {
                ResourceManager.populateDtoFromMap(this, map);
            }

            public InsertParam(JSONObject json) {
                ResourceManager.populateDtoFromMap(this, json);
            }

            public int? Iddr {
                get { return iddr; }
                set { this.iddr = value; }
            }

            public int? Idsolicitud {
                get { return idsolicitud; }
                set { this.idsolicitud = value; }
            }

            public int? Idversion {
                get { return idversion; }
                set { this.idversion = value; }
            }

            public string Idtipodr {
                get { return idtipodr; }
                set { this.idtipodr = value; }
            }

            public void setValuesFromMap(Dictionary<string, string> map) {
                ResourceManager.populateDtoFromMap(this, map);
            }

            public void setValuesFromMap(JSONObject json) {
                ResourceManager.populateDtoFromMap(this, json);
            }

        }

    }
}
